package com.xjggb.io;

import javax.imageio.stream.FileImageOutputStream;
import java.io.*;

public class Demo02 {
    static String  fir= "D:\\lu\\1.txt";
    static String  firJPG= "D:\\lu\\12.png";
    static String  firJP= "C:\\Users\\lenovo\\Pictures\\Saved Pictures\\12.png";
    static String  fi= "D:\\lu";
    public static void main(String[] args) {
        show7();

    }

    public static void show7(){
        FileInputStream fileInputStream=null;
        FileOutputStream fileOutputStream=null;
        try {
            fileOutputStream = new FileOutputStream(new File(firJPG));
            fileInputStream = new FileInputStream(new File(firJP));

            byte[] bytes = new byte[1024 * 1000];
            int len;
            while ((len=fileInputStream.read(bytes))!=-1){
                fileOutputStream.write(bytes,0,len);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileOutputStream.close();
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    System.out.println();
    }

    public static void show6(){
        FileInputStream fileInputStream=null;
        try {
             fileInputStream = new FileInputStream(new File(fir));
            int B;
            while ((B=fileInputStream.read())!=-1) {
                System.out.println("B = " + (char)B);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }

    public static void show5(){
        FileOutputStream fileOutputStream =null;
        try {
            fileOutputStream = new FileOutputStream(new File(fir),false);
//            写入数据
            byte [] in = {'q','w','e','r','t'};

            for (int i = 0; i < in.length; i++) {
                fileOutputStream.write(in[i]);
                fileOutputStream.write("\r\n".getBytes());

            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fileOutputStream!=null){
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println();
    }

    public static void show4(){
        FileOutputStream fileOutputStream =null;
        try {
            fileOutputStream = new FileOutputStream(new File(fir),false);
//            写入数据
            byte [] in = {'q','w','e','r','t'};

            for (int i = 0; i < in.length; i++) {
                fileOutputStream.write(in[i]);
                fileOutputStream.write("\r\n".getBytes());

            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fileOutputStream!=null){
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println();
    }

    public static void show3(){
        FileOutputStream fileImageOutputStream =null;
        try {
            fileImageOutputStream = new FileOutputStream(new File(fir),true);
//            写入数据
            byte[] bytes = "abcdefg".getBytes();
            fileImageOutputStream.write(bytes,2,2);

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fileImageOutputStream!=null){
                try {
                    fileImageOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println();
    }

    public static void show2(){
        FileImageOutputStream fileImageOutputStream =null;
        try {
            fileImageOutputStream = new FileImageOutputStream(new File(fir));
//            写入数据
            byte[] bytes = "qwerty".getBytes();
            fileImageOutputStream.write(bytes,2,2);

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fileImageOutputStream!=null){
                try {
                    fileImageOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println();
    }

    public static void show1(){
         FileImageOutputStream fileImageOutputStream =null;
        try {
            fileImageOutputStream = new FileImageOutputStream(new File(fir));
//            写入数据
            byte[] bytes = "行健挂怪吧".getBytes();
            fileImageOutputStream.write(bytes);

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fileImageOutputStream!=null){
                try {
                    fileImageOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println();
    }
}
